import 'dart:typed_data';

import 'package:flutter_base/common/apis/apis.dart';
import 'package:flutter_base/common/utils/utils.dart';
import 'package:flutter_base/common/values/values.dart';
import 'package:flutter_base/common/widgets/widgets.dart';
import 'package:flutter_base/routes.dart';
import 'package:flutter/material.dart';
import 'package:extended_image/extended_image.dart' as Image;
import 'package:photo_view/photo_view.dart';
import 'package:photo_view/photo_view_gallery.dart';

/*详情菜单*/
class LabelMenu extends StatelessWidget {
  final String? title;
  final String? detail;

  const LabelMenu({Key? key, this.title, this.detail}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return isEmpty(detail!.trim())
        ? Container()
        : Container(
            color: Colors.white,
            child: FractionallySizedBox(
              widthFactor: 1,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Padding(
                    padding: const EdgeInsets.fromLTRB(20, 8, 20, 4),
                    child: Text(
                      title!,
                      style: TextStyle(fontSize: 16, color: Colors.grey[600]),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.fromLTRB(20, 0, 20, 8),
                    child: Text(
                      detail!,
                      style: TextStyle(fontSize: 18),
                    ),
                  )
                ],
              ),
            ),
          );
  }
}

class LabelMenuDetailWidget extends StatelessWidget {
  final String? title;
  final Widget? detail;

  const LabelMenuDetailWidget({Key? key, this.title, this.detail})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return isEmpty(detail)
        ? Container()
        : Container(
            color: Colors.white,
            child: FractionallySizedBox(
              widthFactor: 1,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Padding(
                    padding: const EdgeInsets.fromLTRB(20, 12, 20, 12),
                    child: Text(
                      title!,
                      style: TextStyle(fontSize: 18, color: Colors.grey[600]),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.fromLTRB(20, 0, 20, 12),
                    child: detail,
                  )
                ],
              ),
            ),
          );
  }
}

/*附件*/
class AttachmentsMenu extends StatelessWidget {
  final String? title;
  final String? detail;

  const AttachmentsMenu({Key? key, this.title, this.detail}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: FractionallySizedBox(
        widthFactor: 1,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding: const EdgeInsets.fromLTRB(20, 12, 20, 12),
              child: Text(
                title!,
                style: TextStyle(fontSize: 18, color: Colors.grey[600]),
              ),
            ),
            Padding(
              padding: const EdgeInsets.fromLTRB(20, 12, 50, 12),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  loadAssetImage('fujian',
                      width: zhiSetWidth(40), height: zhiSetWidth(40)),
                  Expanded(
                    child: Padding(
                      padding: const EdgeInsets.fromLTRB(20, 0, 12, 12),
                      child: Text(
                        detail!,
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                        textAlign: TextAlign.start,
                        style: TextStyle(fontSize: 18),
                      ),
                    ),
                  ),
                  Container(
                    child: Text(
                      '预览',
                      style: TextStyle(fontSize: 14, color: Colors.grey),
                    ),
                    padding: EdgeInsets.symmetric(vertical: 2, horizontal: 5),
                    decoration: BoxDecoration(
                      //设置四周圆角 角度
                      borderRadius: BorderRadius.all(Radius.circular(18.0)),
                      //设置四周边框
                      border:
                          new Border.all(width: 2, color: Colors.grey[200]!),
                    ),
                  )
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

/*详情附件cell*/
class AttachmentsDetailMenu extends StatelessWidget {
  final String? title;
  final String? url;
  final bool isImg;
  final List? imgList;
  final int? imgInt;

  const AttachmentsDetailMenu(
      {Key? key,
      this.title,
      this.url,
      this.isImg = false,
      this.imgList,
      this.imgInt})
      : super(key: key);

  void open(BuildContext context, final int index) {
    List<GalleryExampleItem> _list = [];
    for (dynamic item in imgList!) {
      _list.add(GalleryExampleItem(resource: item.url!, id: item.accCode!));
    }
    openWidget(
        context,
        GalleryPhotoViewWrapper(
          galleryItems: _list,
          backgroundDecoration: const BoxDecoration(
            color: Colors.black,
          ),
          initialIndex: index,
          scrollDirection: Axis.horizontal,
        ));
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: isImg ||url!.substring(url!.length-3)=='png'
          ? () {
              open(context, imgInt!);
            }
          : () {
              openWidget(
                  context,
                  FilePreViewWidget(url: getNetWorkImgPath(url),title: title!,)
                  // ZtbWebView(
                  //   url: getNetWorkImgPath(url),
                  // )
              );
            },
      child: Container(
        color: Colors.white,
        child: FractionallySizedBox(
          widthFactor: 1,
          child: Padding(
            padding: const EdgeInsets.fromLTRB(20, 12, 20, 12),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                loadAssetImage('fujian',
                    width: zhiSetWidth(40), height: zhiSetWidth(40)),
                Expanded(
                  child: Padding(
                    padding: const EdgeInsets.fromLTRB(20, 0, 12, 12),
                    child: Text(
                      title!,
                      maxLines: 2,
                      overflow: TextOverflow.ellipsis,
                      textAlign: TextAlign.start,
                      style: TextStyle(fontSize: 18),
                    ),
                  ),
                ),
                // Container(child: Text('预览',style: TextStyle(fontSize: 14,color: Colors.grey),),
                //   padding: EdgeInsets.symmetric(vertical: 2,horizontal: 5),
                //   decoration: BoxDecoration(
                //     //设置四周圆角 角度
                //     borderRadius:
                //     BorderRadius.all(Radius.circular(18.0)),
                //     //设置四周边框
                //     border:
                //     new Border.all(width: 2, color: Colors.grey[200]),
                //   ),)
              ],
            ),
          ),
        ),
      ),
    );
  }
}

/*详情附件模块*/
class AttachmentsDetailWidget extends StatelessWidget {
  final String? title;
  final List? list;
  final bool isImg; //图片附件

  const AttachmentsDetailWidget(
      {Key? key, this.title, this.list, this.isImg = false})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: FractionallySizedBox(
        widthFactor: 1,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding: const EdgeInsets.fromLTRB(20, 12, 20, 0),
              child: Text(
                title!,
                style: TextStyle(fontSize: 18, color: Colors.grey[600]),
              ),
            ),
            ListView.builder(
              padding: EdgeInsets.all(0),
              shrinkWrap: true,
              physics: NeverScrollableScrollPhysics(),
              itemCount: list?.length ?? 0,
              itemBuilder: (BuildContext context, int index) {
                return AttachmentsDetailMenu(
                  title: list![index]?.accName ?? '',
                  isImg: isImg,
                  url: list![index]?.url ?? '',
                  imgList: list,
                  imgInt: index,
                );
              },
            )
          ],
        ),
      ),
    );
  }
}

Widget titleLabel(String title) {
  return FractionallySizedBox(
    widthFactor: 1,
    child: Container(
      child: Text(
        title,
        style: TextStyle(color: Color(0xffa3a3a3)),
      ),
      color: Color(0xfff2f2f2),
      padding: EdgeInsets.fromLTRB(20, 10, 10, 10),
    ),
  );
}

Widget TitleLabel(title) {
  return Container(
//    alignment: Alignment.center,
    width: 120,
//    padding: const EdgeInsets.only(right: 20.0),
    child: Text(
      title,
      textAlign: TextAlign.left,
      // style: AppStyles.FormLabelStyle,
    ),
  );
}

Widget titleLabelMust(title, {bool must = false, double width = 120}) {
  return SizedBox(
    width: width,
    child: Container(
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(
            title,
            textAlign: TextAlign.left,
            // style: AppStyles.FormLabelStyle,
          ),
          Icon(
            Icons.flare,
            size: 5,
            color: must ? Colors.red : Colors.transparent,
          )
        ],
      ),
    ),
  );
}

// Widget LabelMenu(title:String title, String detail, {double width = 100, bool isHasBorder = true}) {
//   return Container(
//     constraints: BoxConstraints(
//       minHeight: 50,
//     ),
//     decoration: BoxDecoration(
//         color: Colors.white,
//         border: isHasBorder ? Border(bottom: BorderSide(color: Colors.grey[100])) : Border()),
// //    height: 50.0,
//     child: Padding(
//       padding: const EdgeInsets.symmetric(horizontal: 20.0),
//       child: SafeArea(
//         top: false,
//         bottom: false,
//         child: Row(
//           mainAxisAlignment: MainAxisAlignment.start,
//           children: <Widget>[
//             Container(
//               width: width,
// //              padding: const EdgeInsets.only(right: 20.0),
//               child: Text(
//                 title,
// //                textAlign: TextAlign.center,
//                 style: TextStyle(fontSize: 16, color: Colors.grey),
//               ),
//             ),
//             Expanded(
//               child: Padding(
//                 padding: const EdgeInsets.only(right: 20.0),
//                 child: Text(
//                   detail,
//                   style: TextStyle(fontSize: 16),
//                 ),
//               ),
//             ),
//           ],
//         ),
//       ),
//     ),
//   );
// }

Widget buildMenuApply(String title, String detail) {
  return Container(
    decoration: BoxDecoration(
        color: Colors.white,
        border: Border(bottom: BorderSide(color: Colors.grey[100]!))),
    height: 50.0,
    child: Padding(
      padding: const EdgeInsets.symmetric(horizontal: 20.0),
      child: SafeArea(
        top: false,
        bottom: false,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            Container(
              width: 120,
//              padding: const EdgeInsets.only(right: 20.0),
              child: Text(
                title,
//                textAlign: TextAlign.center,
                style: TextStyle(
                  fontSize: 16,
                ),
              ),
            ),
            Expanded(
              child: Padding(
                padding: const EdgeInsets.only(right: 20.0),
                child: Text(
                  detail,
                  style: TextStyle(fontSize: 16),
                ),
              ),
            ),
          ],
        ),
      ),
    ),
  );
}

Widget buildComplexMenu(List<Widget> children) {
  return Container(
    decoration: BoxDecoration(
      color: Colors.white,
    ),
    height: 50.0,
    child: Padding(
      padding: const EdgeInsets.symmetric(horizontal: 16.0),
      child: SafeArea(
        top: false,
        bottom: false,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: children,
        ),
      ),
    ),
  );
}

Widget buildTextFieldMenu(List<Widget> children, {bool needBorder = true}) {
  return Column(
    children: [
      Container(
        constraints: BoxConstraints(
          minHeight: 50,
        ),
        decoration: BoxDecoration(
            color: Colors.white,
            border: Border(
                bottom: BorderSide(
                    color: needBorder ? Colors.grey[100]! : Colors.white))),
//    height: 50.0,
        child: Padding(
          padding: EdgeInsets.fromLTRB(zhiSetWidth(15), 0, zhiSetWidth(10), 0),
          child: SafeArea(
            top: false,
            bottom: false,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: children,
            ),
          ),
        ),
      ),
      Container(
        height: needBorder ? zhiSetHeight(7) : 0,
        color: Colors.grey[100],
      )
    ],
  );
}

///新UI
Widget fromField(String title, Widget widget,
    {String? validateString,
    bool needBorder = true,
    bool must = false,
    double height = 75}) {
  return Column(
    children: [
      Container(
        color: Colors.white,
        padding: EdgeInsets.fromLTRB(
            zhiSetWidth(5), zhiSetHeight(10), zhiSetWidth(5), 0),
        height: zhiSetHeight(height),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                SizedBox(
                  width: 5,
                ),
                RichText(
                    text: TextSpan(
                  text: must ? "*" : " ",
                  style: TextStyle(fontSize: 16, color: Colors.red)
                      .copyWith(color: Colors.red),
                  children: [
                    TextSpan(
                      text: title,
                      style: TextStyle(fontSize: 16, color: Colors.black87)
                          .copyWith(color: Colors.black87),
                    )
                  ],
                )),
                SizedBox(
                  width: 5,
                ),
                // Expanded(
                //   child: _buildCupertinoTextField(context),
                // ),
                // row.suffixWidget != null
                //     ? row.suffixWidget(context, row)
                //     : SizedBox.shrink(),
              ],
            ),
            SizedBox(
              height: zhiSetHeight(5),
            ),
            Expanded(
              child: Row(
                children: [
                  SizedBox(
                    width: zhiSetWidth(10),
                  ),
                  widget,
                  SizedBox(
                    width: 5,
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
      isEmpty(validateString)
          ? Container()
          : Container(
              color: Color.fromRGBO(252, 227, 221, 1),
              padding: EdgeInsets.only(left: zhiSetWidth(15)),
              child: FractionallySizedBox(
                  widthFactor: 1,
                  child: Padding(
                    padding: const EdgeInsets.symmetric(horizontal: 4),
                    child: Container(
                      // color: Colors.redAccent[200],
                      child: Text(
                        validateString!,
                        style: TextStyle(
                            fontSize: 12,
                            color: Color.fromRGBO(247, 76, 39, 1)),
                      ),
                    ),
                  )),
            ),
      Container(
        height: needBorder ? zhiSetHeight(7) : 0,
        color: Colors.grey[100],
      )
    ],
  );
}

Widget buildTitleAndTextFieldMenu(String title, Widget widget,
    {bool must = false}) {
  return Container(
    color: Colors.white,
    constraints: BoxConstraints(
      minHeight: 50,
    ),
//    height: 50.0,
    child: Padding(
      padding: const EdgeInsets.symmetric(horizontal: 20.0),
      child: SafeArea(
        top: false,
        bottom: false,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            Stack(
              children: <Widget>[
                Container(
                  width: 100,
//                  padding: const EdgeInsets.only(right: 10.0),
                  child: Text(
                    title,
//                    textAlign: TextAlign.center,
                    style: TextStyle(fontSize: 16),
                  ),
                ),
                Positioned(
                  child: Icon(
                    Icons.flare,
                    size: 5,
                    color: must ? Colors.red : Colors.transparent,
                  ),
                  right: 10,
                  top: 0,
                )
              ],
            ),
            Expanded(
              child: Padding(
                padding: const EdgeInsets.only(right: 20.0),
                child: widget,
              ),
            ),
          ],
        ),
      ),
    ),
  );
}

Widget topicBuildTitleAndTextFieldMenu(String title, Widget widget,
    {bool must = false}) {
  return Container(
    constraints: BoxConstraints(
      minHeight: 50,
    ),
    decoration: BoxDecoration(
        color: Colors.white,
        border: Border(bottom: BorderSide(color: Colors.grey[100]!))),
//    height: 50.0,
    child: Padding(
      padding: const EdgeInsets.symmetric(horizontal: 20.0),
      child: SafeArea(
        top: false,
        bottom: false,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            Stack(
              children: <Widget>[
                Container(
                  width: 120,
//                  padding: const EdgeInsets.only(right: 10.0),
                  child: Text(
                    title,
//                    textAlign: TextAlign.center,
                    style: TextStyle(fontSize: 16, color: Colors.grey),
                  ),
                ),
                Positioned(
                  child: Icon(
                    Icons.flare,
                    size: 5,
                    color: must ? Colors.red : Colors.transparent,
                  ),
                  right: 10,
                  top: 0,
                )
              ],
            ),
            Expanded(
              child: Padding(
                padding: const EdgeInsets.only(right: 20.0),
                child: widget,
              ),
            ),
          ],
        ),
      ),
    ),
  );
}

Widget buildFileMenu(String title, Widget detailWidget,
    {double width = 100, bool isHasBorder = true}) {
  return Container(
    constraints: BoxConstraints(
      minHeight: 50,
    ),
    decoration: BoxDecoration(
        color: Colors.white,
        border: isHasBorder
            ? Border(bottom: BorderSide(color: Colors.grey[100]!))
            : Border()),
//    height: 50.0,
    child: Padding(
      padding: const EdgeInsets.symmetric(horizontal: 20.0),
      child: SafeArea(
        top: false,
        bottom: false,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            Container(
              width: width,
//              padding: const EdgeInsets.only(right: 20.0),
              child: Text(
                title,
//                textAlign: TextAlign.center,
                style: TextStyle(fontSize: 16, color: Colors.grey),
              ),
            ),
            Expanded(
              child: Padding(
                padding: const EdgeInsets.only(right: 20.0),
                child: detailWidget,
              ),
            ),
          ],
        ),
      ),
    ),
  );
}

Widget customLabel(title,
    {Color color = Colors.black87,
    bool autoStyle = false,
    isLink = false,
    double width = 110}) {
  return autoStyle
      ? Expanded(
          child: Text(
            title,
            textAlign: TextAlign.left,
            style: isLink
                ? TextStyle(fontSize: 16, color: AppColors.primaryElement)
                : null,
          ),
        )
      : Container(
          width: width,
          child: Text(
            title,
            textAlign: TextAlign.left,
            style: TextStyle(fontSize: 16.0, color: Colors.grey),
          ),
        );
}

//设置宽度自动折行
Widget wrapLabel(title,
    {Color color = Colors.black87,
    isLink = false,
    double width = 120,
    bool must = false}) {
  return Wrap(
    children: <Widget>[
      SizedBox(
        width: width,
        child: Container(
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                width: width - 5,
                child: Text(
                  title,
                  textAlign: TextAlign.left,
                  style: TextStyle(fontSize: 16.0, color: color),
                ),
              ),
              Icon(
                Icons.flare,
                size: 5,
                color: must ? Colors.red : Colors.transparent,
              )
            ],
          ),
        ),
      ),
    ],
  );
}

//设置宽度自动折行 带高度
Widget buildTextFieldMenuWithHeight(List<Widget> children,
    {bool needBorder = true, double height = 50}) {
  return Container(
    constraints: BoxConstraints(
      minHeight: 50,
    ),
    decoration: BoxDecoration(
        color: Colors.white,
        border: Border(
            bottom: BorderSide(
                color: needBorder ? Colors.grey[100]! : Colors.white))),
    height: height,
    child: Padding(
      padding: const EdgeInsets.symmetric(horizontal: 20.0),
      child: SafeArea(
        top: false,
        bottom: false,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: children,
        ),
      ),
    ),
  );
}

// 退回提示
Widget sendBackText(String text) {
  return FractionallySizedBox(
    widthFactor: 1,
    child: Container(
      decoration: BoxDecoration(
        border: Border(bottom: BorderSide(color: Color(0xffd5caca), width: 0)),
        color: Color(0xfffbeeed),
      ),
      child: Row(
        children: <Widget>[
          SizedBox(
            width: 10,
          ),
          Padding(
            padding: const EdgeInsets.all(10.0),
            child: Icon(
              Icons.info,
              color: Color(0xffe75d58),
            ),
          ),
          Expanded(
              child: Padding(
            padding: const EdgeInsets.all(5.0),
            child: Text(
              '驳回原因:$text',
              style: TextStyle(color: Color(0xff645f5f)),
            ),
          ))
        ],
      ),
    ),
  );
}

///详情title
class DetailTitle extends StatelessWidget {
  @required
  final String? title;
  @required
  final String? userName;

  const DetailTitle({Key? key, this.title, this.userName}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return isEmpty(title!.trim())
        ? Container()
        : Container(
            // color: Colors.white,
            child: Column(
              children: [
                Container(
                  color: Colors.white,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Padding(
                        padding: const EdgeInsets.fromLTRB(20, 12, 12, 12),
                        child: Text(
                          '${title ?? ''}',
                          style: TextStyle(
                            fontSize: 22,
                            fontWeight: FontWeight.w500,
                          ),
                        ),
                      ),
                      Padding(
                        padding: const EdgeInsets.fromLTRB(20, 0, 12, 12),
                        child: Row(
                          children: [
                            Container(
                              margin: EdgeInsets.only(right: 5),
                              width: zhiSetWidth(20),
                              height: zhiSetWidth(20),

                              //边框设置
                              decoration: new BoxDecoration(
                                //背景
                                color: AppColors.primaryElement,
                                //设置四周圆角 角度
                                borderRadius:
                                    BorderRadius.all(Radius.circular(6.0)),
                                //设置四周边框
                              ),
                              child: Center(
                                child: Text(
                                  nickName(userName ?? ''),
                                  style: TextStyle(
                                      fontSize: 8,
                                      color: Colors.white,
                                      fontWeight: FontWeight.w500),
                                ),
                              ),
                            ),
                            Text(userName ??
                                ''
                                    ''),
                          ],
                        ),
                      ),
                      // Padding(
                      //   padding:
                      //       const EdgeInsets.fromLTRB(20, 0, 12, 20),
                      //   child: Text('审批通过'),
                      // )
                    ],
                  ),
                ),
                SizedBox(
                  height: 10,
                  child: Container(
                    color: Colors.grey[100],
                  ),
                ),
              ],
            ),
          );
  }
}

/// 虚线
class DottedLine extends StatelessWidget {
  final double height;
  final Color color;
  final Axis direction;

  const DottedLine({
    this.height = 1,
    this.color = Colors.black,
    this.direction = Axis.horizontal,
  });

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (BuildContext context, BoxConstraints constraints) {
        final boxWidth = direction == Axis.horizontal
            ? constraints.constrainWidth()
            : constraints.constrainHeight();
        final dashWidth = 8.0;
        final dashHeight = height;
        final dashCount = (boxWidth / (2 * dashWidth)).floor();
        return Flex(
          children: List.generate(dashCount, (_) {
            return SizedBox(
              width: direction == Axis.horizontal ? dashWidth : dashHeight,
              height: direction == Axis.horizontal ? dashHeight : dashWidth,
              child: DecoratedBox(
                decoration: BoxDecoration(color: color),
              ),
            );
          }),
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          direction: direction,
        );
      },
    );
  }
}


class GalleryPhotoViewWrapper extends StatefulWidget {
  GalleryPhotoViewWrapper({
    this.loadingBuilder,
    this.backgroundDecoration,
    this.minScale,
    this.maxScale,
    this.initialIndex = 0,
    required this.galleryItems,
    this.scrollDirection = Axis.horizontal,
  }) : pageController = PageController(initialPage: initialIndex);

  final LoadingBuilder? loadingBuilder;
  final BoxDecoration? backgroundDecoration;
  final dynamic minScale;
  final dynamic maxScale;
  final int initialIndex;
  final PageController pageController;
  final List<GalleryExampleItem> galleryItems;
  final Axis scrollDirection;

  @override
  State<StatefulWidget> createState() {
    return _GalleryPhotoViewWrapperState();
  }
}

class _GalleryPhotoViewWrapperState extends State<GalleryPhotoViewWrapper> {
  late int currentIndex = widget.initialIndex;

  void onPageChanged(int index) {
    setState(() {
      currentIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      body: SafeArea(
        child: Container(
          decoration: widget.backgroundDecoration,
          constraints: BoxConstraints.expand(
            height: MediaQuery.of(context).size.height,
          ),
          child: Stack(
            alignment: Alignment.bottomRight,
            children: <Widget>[
              PhotoViewGallery.builder(
                scrollPhysics: const BouncingScrollPhysics(),
                builder: _buildItem,
                itemCount: widget.galleryItems.length,
                loadingBuilder: widget.loadingBuilder,
                backgroundDecoration: widget.backgroundDecoration,
                pageController: widget.pageController,
                onPageChanged: onPageChanged,
                scrollDirection: widget.scrollDirection,
              ),
              Positioned(
                  left: 5,
                  top: zhiSetHeight(20),
                  child: IconButton(
                    icon: Icon(
                      Icons.arrow_back_ios_outlined,
                      color: Colors.white,
                    ),
                    onPressed: () {
                      Navigator.pop(context);
                    },
                  )),
              Container(
                padding: const EdgeInsets.all(20.0),
                child: Text(
                  // "Image ${currentIndex + 1}",
                  "图 ${currentIndex + 1}",
                  style: const TextStyle(
                    color: Colors.white,
                    fontSize: 17.0,
                    decoration: null,
                  ),
                ),
              )
            ],
          ),
        ),
      ),
    );
  }

  PhotoViewGalleryPageOptions _buildItem(BuildContext context, int index) {
    final GalleryExampleItem item = widget.galleryItems[index];
    return PhotoViewGalleryPageOptions(
      imageProvider: NetworkImage(getNetWorkImgPath(item.resource)),
      initialScale: PhotoViewComputedScale.contained,
      // minScale: PhotoViewComputedScale.contained * (0.5 + index / 10),
      minScale: PhotoViewComputedScale.contained,
      maxScale: PhotoViewComputedScale.covered * 4.1,
      heroAttributes: PhotoViewHeroAttributes(tag: index.toString()),
    );
  }
}
class GalleryExampleItem {
  GalleryExampleItem({
    required this.id,
    required this.resource,
    this.isSvg = false,
  });

  final String id;
  final String resource;
  final bool isSvg;
}